<?php
require_once "tool/Mysql.php";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$p = file_exists("../passwd") ? (trim(file_get_contents("../passwd"))) : null;
$db = new  yxmingy\Mysql('localhost',  'root', $p!=null ? $p : '123356');
if($db->connected()) {
	$db->createDatabase("main");
	$db->select_db("main");
	$userinfo_table = new yxmingy\Table("userinfo");
	$userinfo_table->add("`id` INT UNSIGNED AUTO_INCREMENT");
	$userinfo_table->add("`learned_word_count` INT UNSIGNED NOT NULL");
	$userinfo_table->add("`name` VARCHAR(10) NOT NULL");
	$userinfo_table->add("`passwd` VARCHAR(20) NOT NULL");
	$userinfo_table->add("`public_cache` VARCHAR(4096) NOT NULL");
	$userinfo_table->add("UNIQUE KEY (`id`)");
	$userinfo_table->setAddition("DEFAULT CHARSET=utf8;");
	$db->createTable($userinfo_table);
	$wordlist_table = new yxmingy\Table("wordlist");
	$wordlist_table->add("`owner_name` VARCHAR(10) NOT NULL");
	$wordlist_table->add("`list_id` INT UNSIGNED NOT NULL");
	$wordlist_table->add("`public_index` VARCHAR(15)");
	$wordlist_table->add("`text` VARCHAR(20000)");
	$wordlist_table->setAddition("DEFAULT CHARSET=utf8;");
	$db->createTable($wordlist_table);
	$publiclist_table = new yxmingy\Table("publiclist");
	$publiclist_table->add("`list_id` INT UNSIGNED AUTO_INCREMENT");
    $publiclist_table->add("`name` VARCHAR(30) NOT NULL");
	$publiclist_table->add("`text` MEDIUMTEXT");
	$publiclist_table->add("UNIQUE KEY (`list_id`)");
	$publiclist_table->setAddition("DEFAULT CHARSET=utf8;");
	$db->createTable($publiclist_table);
	echo "Initialization Succeed.";
}else{
	echo $db->getConnectError();
}
$db->close();
